package com.jiang.controller;

import com.alibaba.fastjson.JSON;
import com.jiang.dao.userimpl;
import com.jiang.entity.Type;
import com.jiang.service.Administratorimpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author jiangjingbo
 * @version V1.0
 * @Project java2203
 * @Package com.jiang.controller
 * @Description:
 * @Date 2022/5/24 16:24
 */
@WebServlet("/type")
public class TypeController extends  BaseServlet{
    /**
     * 查看商品类
      * @param request
     * @param response
     * @return
     */
    public String findAllType(HttpServletRequest request, HttpServletResponse response){
        //调用业务程
        Administratorimpl ad = new Administratorimpl(new userimpl());
        //查看所有
        List<Type> type = ad.findAllType();
        System.out.println("=====allTYpe======="+type);
        request.getSession().setAttribute("goodsTypeList",type);
        return "forward:/admin/showGoodsType.jsp";
}


    public void findAll(HttpServletRequest request,HttpServletResponse response) throws IOException {
        Administratorimpl administratorimpl = new Administratorimpl(new userimpl());
        List<Type> allType = administratorimpl.findAllType();
        //java代码装换为json 形式
        String string = JSON.toJSONString(allType);
        //用流将它写回去
        response.getWriter().write(string);
    }

}
